﻿package com.gengine.utils.pools
{
    import flash.utils.*;

    public class ObjectPool extends Object
    {
        private static var pools:Dictionary = new Dictionary();

        public function ObjectPool()
        {
            return;
        }// end function

        public static function getPool(param1:Class) : Array
        {
            return param1 in pools ? (pools[param1]) : (var _loc_2:* = new Array(), pools[param1] = new Array(), _loc_2);
        }// end function

        public static function getObject(param1:Class, ... args)
        {
            var _loc_4:Object = null;
            args = getPool(param1);
            if (args.length > 0)
            {
                _loc_4 = args.pop();
            }
            else
            {
                _loc_4 = construct(param1, args);
            }
            if (_loc_4.hasOwnProperty("_eventFlags"))
            {
                throw new Error("error in ObjectPools，请改用FrObjectPool.getObject");
            }
            return _loc_4;
        }// end function

        public static function disposeObject(param1, param2:Class = null) : void
        {
            var _loc_4:String = null;
            if (param1.hasOwnProperty("_eventFlags"))
            {
                throw new Error("error in ObjectPools，请改用FrObjectPool.disposeObject");
            }
            if (!param2)
            {
                _loc_4 = getQualifiedClassName(param1);
                param2 = getDefinitionByName(_loc_4) as Class;
            }
            var _loc_3:* = getPool(param2);
            if (_loc_3.indexOf(param1) == -1)
            {
                _loc_3.push(param1);
            }
            return;
        }// end function

        public static function hasDisposeObject(param1, param2:Class = null) : Boolean
        {
            var _loc_4:String = null;
            if (!param2)
            {
                _loc_4 = getQualifiedClassName(param1);
                param2 = getDefinitionByName(_loc_4) as Class;
            }
            var _loc_3:* = getPool(param2);
            return _loc_3.indexOf(param1) != -1;
        }// end function

        public static function getPoolMsg() : String
        {
            var _loc_3:* = undefined;
            var _loc_4:Array = null;
            var _loc_1:String = "";
            var _loc_2:int = 0;
            for (_loc_3 in pools)
            {
                
                _loc_4 = getPool(_loc_3);
                _loc_2 = _loc_2 + _loc_4.length;
                _loc_1 = _loc_1 + (_loc_3 + ":<font color=\'#00FF00\'>" + _loc_4.length + "</font>\n");
            }
            return "对象池总对象数量：<font color=\'#00FF00\'>" + _loc_2 + "</font>\n" + _loc_1;
        }// end function

        public static function clearPool() : void
        {
            pools = new Dictionary();
            return;
        }// end function

    }
}
